home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / PLASMA3.ZIP / PLASMA3.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-07-16  |  26.8 KB  |  1,121 lines

  1. ;Hi-res plasma code.  (c) Alex Allmont (AKA btf) 1995  aallmont@plym.ac.uk
  2. ;Not SVGA, just pretty darned hi-res VGA mode-x trickery!
  3. ;Because of the HUUUUUGGE amounts of data being dumped to the screen, this
  4. ;code is only really happy on a hefty machine.
  5.  
  6. ;The 'plasma' is just a load of sine waves along x and y, thrown together in
  7. ;a reckless manner.  That's not a totally great description, but if you can't
  8. ;suss it out...TOUGH!
  9.  
  10.     .model medium
  11.     .386
  12.     .dosseg
  13.     .stack
  14.     .data
  15.  
  16. SCREEN_SIZE EQU 400*80
  17.  
  18. ESCAPE    EQU    01h        ;Scancodes
  19. CUR_UP    EQU    48h
  20. CUR_DN    EQU    50h
  21. CUR_LF    EQU    4bh
  22. CUR_RT    EQU    4dh
  23. CTRL    EQU    1dh
  24. ALT    EQU    38h
  25. DELETE    EQU    53h
  26.  
  27. ;██▓▒░ ░    Structures used to store plasma data
  28. ;Each wave is defined as a starting angle; 'theta', an amplitute; 'amp', and
  29. ;a frequency' 'freq', (though it merely a relative measure).  The change in
  30. ;theta per cycle is given by 'dtheta'
  31. wave    STRUCT
  32.     theta    dw  ?        ;Current angle at which wave starts
  33.     amp    dw  ?        ;Amplitude of wave
  34.     freq    dw  ?        ;Sampling rate along curve => frequency
  35.     dtheta    dw  ?        ;Change in theta per cycle
  36. wave    ENDS
  37.  
  38. LENWAVE EQU    200
  39. ;'wave4' stores 4 separate waves.  The below routines manipulate each of these
  40. ;and sum and store the output into one wave, stored in 'output'
  41. wave4    STRUCT
  42.     wave0    wave    <?,?,?,?>
  43.     wave1    wave    <?,?,?,?>
  44.     wave2    wave    <?,?,?,?>
  45.     wave3    wave    <?,?,?,?>
  46.     output    db    LENWAVE DUP (?)
  47. wave4    ENDS
  48.  
  49. ;██▓▒░ ░    Wave info
  50. xwave1    wave4    <<0,40,1,5>,<30,50,2,4>,<71,18,8,2>,<1,18,7,3>>
  51. ywave1    wave4    <<10,50,2,3>,<450,30,3,5>,<110,26,3,8>,<150,20,13,7>>
  52. xwave2    wave4    <<40,30,3,-2>,<80,60,2,-3>,<291,16,2,-1>,<51,20,11,-4>>
  53. ywave2    wave4    <<100,40,3,5>,<45,40,3,8>,<10,22,11,11>,<150,26,5,13>>
  54.  
  55. ;Pointer to current wave to calculate
  56. curwave dw    OFFSET xwave1
  57. curlen    dw    200    ;length of current wave
  58.  
  59. ;'detail' relates to the zoom ratio, it actually scales down the angle within
  60. ;the wave building routine.  'grain' has the effect of adding more 'bands' of
  61. ;colour to each contour of plasma
  62. detail    db    2
  63. grain    db    13
  64.  
  65. ;INT 9 INFO - key is a table of keys, 1 if hit, 0 if not
  66. ;currentkey is the most recent keypress
  67. ;lastkey is used as a cache to prevent keyboard repeat
  68. key    db    128 dup (0)
  69. currentkey    db    0
  70. lastkey    db    0
  71.  
  72. ;Palette data
  73. pal    db    'pal',768-3 dup (0)
  74.  
  75. ;End text
  76. txt1    db    'Use the cursors to alter zoom/grain.   btf / Esponge - aallmont@plym.ac.uk.'
  77. txt1l    dw    $-txt1
  78.  
  79. ;Insults to the minorities...
  80. crapPC1 db    "Wha?  No VGA card?  Blimey...$"
  81. crapPC2 db    "Tum tee tum, tee-tum tee too, your machine is a piece of poo.  I WANNA 386!$"
  82.  
  83. ;A 'virtual' screen is employed.  This 320x200 mode uses approximately half of
  84. ;the total video memory, so the code writes to a part of the video mem that is
  85. ;currently off (pointed to by soff1) screen and then uses a hardware scroll to
  86. ;do a fast pan to that part of the video memory (yoff1).  - ie FLICKER FREE!
  87. yoff1    dw    400        ;Current y offset of screen
  88. yoff2    dw    0
  89. soff1    dw    400*80        ;Offset of screen at which to write data
  90. soff2    dw    0
  91.  
  92. filename    db    40 dup (0)  ;filename of palette if specified at com-line.
  93. txt2    db    'Error opening palette file.$'
  94.  
  95.     .code
  96.  
  97. ;██▓▒░ ░    Select plane macro
  98. plane    MACRO    reg
  99.     mov dx, 03c4h
  100.     mov ah, reg
  101.     mov al, 02h
  102.     out dx, ax
  103.     ENDM
  104.  
  105.     .startup
  106.  
  107. ;██▓▒░ ░    Main code segment
  108. main    PROC    FAR
  109.  
  110.     call OKmachine        ;Is machine good enough?
  111.     call commandline    ;Get what the user says, if anything
  112.  
  113.     call init_int8        ;Init timer
  114.     call init_int9        ;Init keyboard
  115.     call initgraph        ;Init graphics
  116.  
  117. m0:    call buildwaves     ;Construct waves
  118.     call plotplasma     ;Plot the output to the video planes
  119.     call getkeyinfo     ;User input
  120.     cmp key[ESCAPE], 0  ;escape not recieved?
  121.     je  m0
  122.  
  123.     call deinitgraph    ;Restore graphics
  124.     call deinit_int9    ;Restore keyboard
  125.     call deinit_int8    ;Restore timer
  126.  
  127. main    ENDP
  128.  
  129.     .exit
  130.  
  131.  
  132. ;██▓▒░ ░    Check machine stats
  133. OKmachine   PROC    NEAR        ;Check for 386+, thanks to
  134.     push sp                ;Psi for the code.
  135.     pop dx
  136.     cmp dx, sp
  137.     jz  o1
  138. o2:    jmp need386
  139. o1:    mov bx, OFFSET xwave1.output
  140.     sgdt ds:[bx]            ;Don't understand this bit,
  141.     cmp byte ptr ds:[bx+5],0    ;though %-/  Protected mode goobers!
  142.     js  o2
  143.  
  144.     mov ax, 1A00h            ;Check for VGA
  145.     int 10h
  146.     cmp al, 1Ah
  147.     jne needVGA
  148.     cmp bl, 07h
  149.     jb  needVGA
  150.     ret
  151.  
  152. ;PC not good enough.  Return -1
  153. needVGA:
  154.     mov ah, 09h
  155.     mov dx, OFFSET crapPC1
  156.     int 21h
  157.     mov ax, 4cffh
  158.     int 21h
  159.  
  160. need386:
  161.     mov ah, 09h
  162.     mov dx, OFFSET crapPC2
  163.     int 21h
  164.     mov ax, 4cffh
  165.     int 21h
  166.  
  167. OKmachine   ENDP
  168.  
  169.  
  170. ;██▓▒░ ░    Get command line info - was another palette file specified?
  171. commandline PROC    NEAR
  172.  
  173.     push es
  174.     mov ah, 51h        ;Get PSP
  175.     int 21h
  176.  
  177.     push ds
  178.     push ds
  179.     pop es
  180.     mov ds, bx        ;es=data seg, ds=PSP
  181.  
  182.     mov si, 128        ;Beginning of text in PSP
  183.     lodsb
  184.  
  185.     xor ah, ah        ;Any text at command line?
  186.     xor cx, cx
  187.     mov cl, al
  188.     or  cx, cx        ;(cx=no chars)
  189.     jz  cl1
  190.     cmp cx, 38
  191.     jg  cl1
  192.  
  193.     dec cx
  194.     inc si
  195.     mov di, OFFSET filename     ;Get filename in psp > filename
  196.     cld
  197. rep    movsb
  198.  
  199.     pop ds
  200.     pop es
  201.  
  202.     mov dx, OFFSET filename     ;Open filename
  203.     mov al, 0
  204.     mov ah, 3dh
  205.     int 21h
  206.     jc  diskerror
  207.     mov bx, ax            ;Load in palette > pal
  208.     mov dx, OFFSET pal
  209.     mov cx, 768
  210.     mov ah, 3fh
  211.     int 21h
  212.     jc  diskerror
  213.     ret
  214.  
  215. cl1:    pop ds            ;Exit with no effect
  216.     pop es
  217.     ret
  218.  
  219. diskerror:            ;Cripes!  Disk error.  Exit to dos and cry
  220.     mov ah, 09h
  221.     mov dx, OFFSET txt2
  222.     int 21h
  223.     .exit
  224.  
  225. commandline ENDP
  226.  
  227.  
  228. ;██▓▒░ ░    ;Operate on different keypresses
  229. getkeyinfo  PROC    NEAR
  230.  
  231.     .if key[CUR_UP]==1 && lastkey!=CUR_UP
  232.     dec detail
  233.     .if detail>128
  234.     mov detail, 0
  235.     .endif
  236.     .endif
  237.  
  238.     .if key[CUR_DN]==1 && lastkey!=CUR_DN
  239.     inc detail
  240.     .if detail>3
  241.     mov detail, 3
  242.     .endif
  243.     .endif
  244.  
  245.     .if key[CUR_RT]==1 && lastkey!=CUR_RT
  246.     dec grain
  247.     .if grain<9
  248.     mov grain, 9
  249.     .endif
  250.     .endif
  251.  
  252.     .if key[CUR_LF]==1 && lastkey!=CUR_LF
  253.     inc grain
  254.     .if grain>16
  255.     mov grain, 16
  256.     .endif
  257.     .endif
  258.  
  259.     ;Just in case the user panics!
  260.     .if key[CTRL]==1 && key[ALT]==1 && key[DELETE]==1
  261.     mov key[ESCAPE], 1
  262.     .endif
  263.  
  264.     mov al, currentkey
  265.     mov lastkey, al
  266.  
  267.     ret
  268.  
  269. getkeyinfo  ENDP
  270.  
  271.  
  272. ;----------------KEYBOARD HANDLER STUFF-----------------------------------
  273. oldint9 dd  ?        ;address of old interrupt
  274.  
  275. ;██▓▒░ ░    Install new handler
  276. init_int9   PROC    NEAR
  277.  
  278.     cli
  279.     mov ax, 0
  280.     mov gs, ax
  281.     mov eax, gs:[4*9]            ;store old interrupt
  282.     mov cs:oldint9, eax
  283.     mov ax, cs                ;newint address in eax
  284.     shl eax, 16
  285.     mov ax, OFFSET int9
  286.     mov gs:[4*9], eax            ;store new int
  287.     sti
  288.  
  289.     ret
  290.  
  291. init_int9   ENDP
  292.  
  293.  
  294. ;██▓▒░ ░    Reinstall old handler
  295. deinit_int9 PROC    NEAR
  296.  
  297.     cli
  298.     mov ax, 0
  299.     mov gs, ax
  300.     mov eax, cs:oldint9
  301.     mov gs:[4*9], eax            ;store new int
  302.     sti
  303.  
  304.     ret
  305.  
  306. deinit_int9    ENDP
  307.  
  308.  
  309. ;██▓▒░ ░    New keyboard routine.  Stores table of active keys in 'key'
  310. int9    PROC    NEAR
  311.  
  312.     cli
  313.     push ax
  314.     push bx
  315.     push ds
  316.     mov ax, DGROUP
  317.     mov ds, ax
  318.     in  al, 60h        ;Get scancode
  319.     mov currentkey, al    ;Current key
  320.     mov bl, al
  321.     mov bh, 0
  322.     .if bl<80h
  323.     mov key[bx], 1        ;Store a hit
  324.     .else
  325.     mov key[bx-80h], 0    ;Store a release
  326.     .endif
  327.  
  328.     in  al, 61h        ;Acknowledge interrupt
  329.     mov ah, al
  330.     or  al, 80h
  331.     out 61h, al
  332.     mov al, ah
  333.     out 61h, al
  334.  
  335.     pop ds
  336.     pop bx
  337.     mov al,20h
  338.     out 20h,al
  339.     pop ax
  340.     sti
  341.  
  342.     iret
  343.  
  344. int9    ENDP
  345.  
  346. ;------------INTERRUPT 8 HANDLER STUFF(timer) ------------------------------
  347. oldint8 dd  ?        ;Address of old interrupt
  348.  
  349. ;██▓▒░ ░    install new timer int.    runs at 70Hz approx
  350. init_int8   PROC    NEAR
  351.  
  352.     mov ax, 0
  353.     mov gs, ax
  354.  
  355.     mov eax, gs:[4*8]            ;store old interrupt
  356.     mov cs:oldint8, eax
  357.  
  358.     mov ax, cs                ;newint address in eax
  359.     shl eax, 16
  360.     mov ax, OFFSET int8
  361.     mov dx, 17000                ;70 Hz
  362.     cli
  363.     mov gs:[4*8], eax            ;store new int
  364.  
  365.     mov al, 036h            ;dx=freq
  366.     out 43h, al
  367.     mov al, dl
  368.     out 40h, al
  369.     mov al, dh
  370.     out 40h, al
  371.     sti
  372.  
  373.     ret
  374.  
  375. init_int8   ENDP
  376.  
  377.  
  378. ;██▓▒░ ░    Restore timer
  379. deinit_int8 PROC    NEAR
  380.  
  381.     mov ax, 0
  382.     mov gs, ax
  383.  
  384.     mov eax, cs:oldint8
  385.     mov dx, 0
  386.  
  387.     cli
  388.     mov gs:[4*8], eax            ;store new int
  389.  
  390.     mov al, 036h            ;dx=freq
  391.     out 43h, al
  392.     mov al, dl
  393.     out 40h, al
  394.     mov al, dh
  395.     out 40h, al
  396.     sti
  397.  
  398.     ret
  399.  
  400. deinit_int8    ENDP
  401.  
  402. ;██▓▒░ ░    New handler, increments the sine angles.
  403. int8    PROC    NEAR
  404.  
  405.     cli
  406.     push ax
  407.     push cx
  408.     push si
  409.     push ds
  410.     mov ax, DGROUP
  411.     mov ds, ax
  412.  
  413.     mov si, OFFSET xwave1
  414.     call add4waveoff
  415.     mov si, OFFSET ywave1
  416.     call add4waveoff
  417.     mov si, OFFSET xwave2
  418.     call add4waveoff
  419.     mov si, OFFSET ywave2
  420.     call add4waveoff
  421.  
  422.     pop ds
  423.     pop si
  424.     pop cx
  425.     mov al, 20h        ;this be end of interrupt
  426.     out 20h, al
  427.     pop ax
  428.  
  429.     sti
  430.     iret                ;interrupt return
  431.  
  432. int8    ENDP
  433.  
  434.  
  435. ;██▓▒░ ░    Routine to add all the offsets in one wave
  436. add4waveoff PROC    NEAR
  437.  
  438.     mov cx, 4
  439. a4wo:    mov ax, [si+6]
  440.     add [si], ax
  441.     add si, 8
  442.     dec cx
  443.     jnz a4wo
  444.  
  445.     ret
  446.  
  447. add4waveoff ENDP
  448.  
  449. ;---------------------------------------------------------------------------
  450.  
  451.  
  452. ;██▓▒░ ░    Builds all the waves
  453. buildwaves  PROC    NEAR
  454.  
  455.     mov ax, OFFSET xwave1
  456.     mov curwave, ax
  457.     mov curlen, 160
  458.     call buildwave
  459.  
  460.     mov ax, OFFSET ywave1
  461.     mov curwave, ax
  462.     mov curlen, 200
  463.     call buildwave
  464.  
  465.     mov ax, OFFSET xwave2
  466.     mov curwave, ax
  467.     mov curlen, 160
  468.     call buildwave
  469.  
  470.     mov ax, OFFSET ywave2
  471.     mov curwave, ax
  472.     mov curlen, 200
  473.     call buildwave
  474.  
  475.     ret
  476.  
  477. buildwaves  ENDP
  478.  
  479.  
  480. ;██▓▒░ ░   Builds the wave pointed to by 'curwave'
  481. buildwave   PROC    NEAR
  482.  
  483.     mov si, curwave
  484.     mov di, si
  485.     add di, 8*4        ;di points to output
  486.  
  487.     mov cx, curlen        ;Clear the current contents
  488.     shr cx, 2
  489.     push di
  490.     push es
  491.     push ds
  492.     pop es
  493.     mov eax, 0
  494. rep    stosd
  495.     pop es
  496.     pop di
  497.  
  498.     mov cx, 4        ;4 waves to add up
  499. bw0:    push di
  500.     push cx
  501.  
  502.     mov cx, curlen
  503.     mov bx, [si]
  504. bw1:    push bx
  505.     push cx
  506.     shl bx, 1        ;\
  507.     mov cl, detail        ; }(has the effect of zooming in)
  508.     shr bx, cl        ;/
  509.     call sine
  510.     mov ax, [si+2]        ;Mul by amplitude
  511.     imul bx
  512.     mov cl, grain        ;\Has the effect of adding more 'bands'
  513.     shrd ax, dx, cl     ;/
  514.     pop cx
  515.     add [di], al        ;Add to output
  516.     pop bx
  517.     add bx, [si+4]        ;Add frequency to current theta
  518.     inc di
  519.     dec cx
  520.     jnz bw1
  521.  
  522.     add si, 8        ;Onto next wave
  523.     pop cx
  524.     pop di
  525.     dec cx
  526.     jnz bw0
  527.  
  528.     ret
  529.  
  530. buildwave   ENDP
  531.  
  532.  
  533. ;-----------VIDEO SCMOOO-----------------------------------------------------
  534.  
  535. ;██▓▒░ ░    Set VGA 320x400x256 cols, es=video seg, also sets up 'rows' table
  536. ;        sets palette as data in pal
  537. initgraph   PROC    NEAR
  538.  
  539.     mov ax, 13h            ;VGA
  540.     int 10h
  541.     call chain4            ;Tweak 'im
  542.  
  543.     mov ax, 0a000h
  544.     mov es, ax
  545.  
  546.     plane 1111b            ;Clear alllllll memory
  547.     mov eax, 0
  548.     mov cx, 80*400/4
  549.     mov di, 0
  550. rep    stosd
  551.  
  552.     call waitv            ;Contemplate for a bit
  553.     call waitv
  554.  
  555.     mov al, 0            ;Palette
  556.     mov dx, 3c8h
  557.     out dx, al
  558.     inc dx
  559.     mov cx, 768
  560.     mov si, OFFSET pal
  561. rep    outsb
  562.  
  563.     ret
  564.  
  565. initgraph   ENDP
  566.  
  567.  
  568. ;██▓▒░ ░    Return to standard DOS mode 3
  569. deinitgraph PROC    NEAR
  570.  
  571.     mov ax, 03h            ;Dos mode
  572.     int 10h
  573.  
  574.     mov ax, 0b800h            ;Endtext - gotta get my name on it <g!>
  575.     mov es, ax
  576.     mov si, OFFSET txt1
  577.     mov cx, txt1l
  578.     mov di, 0
  579.     mov ah, 0ah
  580. dig0:    lodsb
  581.     stosw
  582.     dec cx
  583.     jnz dig0
  584.  
  585.     ret
  586.  
  587. deinitgraph ENDP
  588.  
  589.  
  590. ;██▓▒░ ░    Plonk video into a 320x400x256 col modex mode
  591. ;        just remembered - these tweaks are from Dreaden/VLA, so I'll give
  592. ;        him a huuuuge amount of credit fo them!  TA!
  593. ;        (I think it's from an archive called modex.zip or something...)
  594. tweaks    LABEL    word
  595.  
  596.     dw        04009h  ; cell height
  597.     dw      00014h  ; turn off dword mode
  598.     dw      0e317h  ; turn on byte mode
  599.  
  600. chain4    PROC    NEAR
  601.  
  602. ;do right bits to unchain
  603.     mov dx, 03c4h
  604.     mov al, 4
  605.     out dx, al
  606.     inc dx
  607.     in  al, dx
  608.     and al, 11110111b
  609.     out dx, al
  610.  
  611. ;disable word/doubleword (I don't know why)
  612.     mov dx, 03d4h
  613.     mov ax, 0e317h
  614.     out dx, ax
  615.     mov ax, 0014h
  616.     out dx, ax
  617.  
  618. ;320x400
  619.     mov dx, 3c2h            ;Set dot clock
  620.     mov al, 0e3h
  621.     out dx, al
  622.  
  623.     mov dx, 3d4h            ;Tweaks
  624.     mov cx, 3
  625.     xor si, si
  626. tw:    mov ax, cs:tweaks[si]
  627.     out dx, ax
  628.     inc si
  629.     inc si
  630.     loop tw
  631.  
  632.     ret
  633.  
  634. chain4    ENDP
  635.  
  636.  
  637. ;██▓▒░ ░    Scroll screen up by yoff
  638. pos    PROC    NEAR
  639.  
  640.     mov ax, yoff1
  641.     mov bx, 80
  642.     mul bx
  643.     mov bx, ax
  644.  
  645.     mov dx, 03d4h
  646.     mov al, 0ch
  647.     out dx, al
  648.     inc dx
  649.     mov al, bh
  650.     out dx, al
  651.  
  652.     dec dx
  653.     mov al, 0dh
  654.     out dx, al
  655.     inc dx
  656.     mov al, bl
  657.     out dx, al
  658.  
  659.     ret
  660.  
  661. pos    ENDP
  662.  
  663.  
  664. ;██▓▒░ ░    Plot plasma from data
  665. ;        this form of 'plasma' is essentially a mad combination of sine
  666. ;        waves.  This code creates it's image from 2 sets of waves.  Each
  667. ;        'set' of waves consists of two waves, one running along x, the
  668. ;        other along y, these are added to obtain a colour at point (x,y).
  669. ;        The actual waves along x and y are built up from sampling 4 sine
  670. ;        waves of various amplitude and frequency into one wave.  (see
  671. ;        'buildwave').
  672. ;        The 2 sets of waves create two separate images, but the high
  673. ;        resolution/subtle colours fool the eye a little into thinking it's
  674. ;        just one smooth image (I hope!). The waves are put together with
  675. ;        the following pattern:
  676. ;            X  -->
  677. ;             0      1    2     3
  678. ;            ---- ----- ----- -----        1/2 = separate sets of
  679. ;         Y    0 | 1-2 | 1-2 | 1-2 | 1-2 |            colours
  680. ;          | 2-1 | 2-1 | 2-1 | 2-1 |
  681. ;         |        ---- ----- ----- -----
  682. ;         V    1 | 1-2 | 1-2 | 1-2 | 1-2 |
  683. ;          | 2-1 | 2-1 | 2-1 | 2-1 |
  684. ;            ---- ----- ----- -----
  685. ;
  686. ;
  687. ;        ...Hmm, that doesn't make much sence, does it?  <g!> Essentially,
  688. ;        it dithers one 'pixel' from two colours, arranged diagonally in a
  689. ;        four pixel set.
  690. ;        Though it's probably hard to see this from what's below...    ;)
  691. ;        that's because this all started out as one loop, but to make the
  692. ;        dithering work and to optimize it for writing to separate planes,
  693. ;        it's all become very convoluted and become 8 separate loops.
  694. ;
  695. ;        btw, it tried not writing directly to the video buffer, using a
  696. ;        chunk of memory to write to and then doing a 'fast' copy to video
  697. ;        memory using a 'movsd' instruction, but on the whole it didn't
  698. ;        make much difference, I think it actually slowed it down a bit.
  699. ;        - & soaked up a big wodge of memory.  So I dumped that idea.
  700. ;
  701. plotplasma  PROC    NEAR
  702.  
  703. ;-----------PLANE 1
  704.     plane 1000b
  705.  
  706.     mov di, soff1
  707.     mov si, OFFSET xwave1
  708.     add si, 8*4+1
  709.     mov bx, OFFSET ywave1
  710.     add bx, 8*4
  711.  
  712.     mov cx, 200
  713. pp0:    push cx
  714.     push si
  715.  
  716.     mov cx, 80
  717. pp1:    mov al, [si]
  718.     add al, [bx]
  719.     add al, 128
  720.     mov es:[di], al
  721.     inc di
  722.     add si, 2
  723.     dec cx
  724.     jnz pp1
  725.  
  726.     inc bx
  727.     add di, 80
  728.     pop si
  729.     pop cx
  730.     dec cx
  731.     jnz pp0
  732.  
  733.  
  734.     mov di, 80
  735.     add di, soff1
  736.     mov si, OFFSET xwave2
  737.     add si, 8*4+1
  738.     mov bx, OFFSET ywave2
  739.     add bx, 8*4
  740.  
  741.     mov cx, 200
  742. pp0a:    push cx
  743.     push si
  744.  
  745.     mov cx, 80
  746. pp1a:    mov al, [si]
  747.     add al, [bx]
  748.     add al, 128
  749.     mov es:[di], al
  750.     inc di
  751.     add si, 2
  752.     dec cx
  753.     jnz pp1a
  754.  
  755.     inc bx
  756.     add di, 80
  757.     pop si
  758.     pop cx
  759.     dec cx
  760.     jnz pp0a
  761.  
  762.  
  763. ;---------- PLANE 2
  764.     plane 0100b
  765.  
  766.     mov di, soff1
  767.     mov si, OFFSET xwave1
  768.     add si, 8*4+1
  769.     mov bx, OFFSET ywave1
  770.     add bx, 8*4
  771.  
  772.     mov cx, 200
  773. pp0b:    push cx
  774.     push si
  775.  
  776.     mov cx, 80
  777. pp1b:    mov al, [si]
  778.     add al, [bx]
  779.     add al, 128
  780.     mov es:[di+80], al
  781.     inc di
  782.     add si, 2
  783.     dec cx
  784.     jnz pp1b
  785.  
  786.     inc bx
  787.     add di, 80
  788.     pop si
  789.     pop cx
  790.     dec cx
  791.     jnz pp0b
  792.  
  793.  
  794.     mov di, 80
  795.     add di, soff1
  796.     mov si, OFFSET xwave2
  797.     add si, 8*4+1
  798.     mov bx, OFFSET ywave2
  799.     add bx, 8*4
  800.  
  801.     mov cx, 200
  802. pp0ab:    push cx
  803.     push si
  804.  
  805.     mov cx, 80
  806. pp1ab:    mov al, [si]
  807.     add al, [bx]
  808.     add al, 128
  809.     mov es:[di-80], al
  810.     inc di
  811.     add si, 2
  812.     dec cx
  813.     jnz pp1ab
  814.  
  815.     inc bx
  816.     add di, 80
  817.     pop si
  818.     pop cx
  819.     dec cx
  820.     jnz pp0ab
  821.  
  822.  
  823.  
  824. ;---------PLANE 3
  825.     plane 0010b
  826.  
  827.     mov di, soff1
  828.     mov si, OFFSET xwave1
  829.     add si, 8*4
  830.     mov bx, OFFSET ywave1
  831.     add bx, 8*4
  832.  
  833.     mov cx, 200
  834. pp01:    push cx
  835.     push si
  836.  
  837.     mov cx, 80
  838. pp11:    mov al, [si]
  839.     add al, [bx]
  840.     add al, 128
  841.     mov es:[di], al
  842.     inc di
  843.     add si, 2
  844.     dec cx
  845.     jnz pp11
  846.  
  847.     inc bx
  848.     add di, 80
  849.     pop si
  850.     pop cx
  851.     dec cx
  852.     jnz pp01
  853.  
  854.  
  855.     mov di, 80
  856.     add di, soff1
  857.     mov si, OFFSET xwave2
  858.     add si, 8*4
  859.     mov bx, OFFSET ywave2
  860.     add bx, 8*4
  861.  
  862.     mov cx, 200
  863. pp01a:    push cx
  864.     push si
  865.  
  866.     mov cx, 80
  867. pp11a:    mov al, [si]
  868.     add al, [bx]
  869.     add al, 128
  870.     mov es:[di], al
  871.     inc di
  872.     add si, 2
  873.     dec cx
  874.     jnz pp11a
  875.  
  876.     inc bx
  877.     add di, 80
  878.     pop si
  879.     pop cx
  880.     dec cx
  881.     jnz pp01a
  882.  
  883.  
  884. ;-------- PLANE 4
  885.     plane 0001b
  886.  
  887.     mov di, soff1
  888.     mov si, OFFSET xwave1
  889.     add si, 8*4
  890.     mov bx, OFFSET ywave1
  891.     add bx, 8*4
  892.  
  893.     mov cx, 200
  894. pp01b:    push cx
  895.     push si
  896.  
  897.     mov cx, 80
  898. pp11b:    mov al, [si]
  899.     add al, [bx]
  900.     add al, 128
  901.     mov es:[di+80], al
  902.     inc di
  903.     add si, 2
  904.     dec cx
  905.     jnz pp11b
  906.  
  907.     inc bx
  908.     add di, 80
  909.     pop si
  910.     pop cx
  911.     dec cx
  912.     jnz pp01b
  913.  
  914.  
  915.     mov di, 80
  916.     add di, soff1
  917.     mov si, OFFSET xwave2
  918.     add si, 8*4
  919.     mov bx, OFFSET ywave2
  920.     add bx, 8*4
  921.  
  922.     mov cx, 200
  923. pp01ab:    push cx
  924.     push si
  925.  
  926.     mov cx, 80
  927. pp11ab:    mov al, [si]
  928.     add al, [bx]
  929.     add al, 128
  930.     mov es:[di-80], al
  931.     inc di
  932.     add si, 2
  933.     dec cx
  934.     jnz pp11ab
  935.  
  936.     inc bx
  937.     add di, 80
  938.     pop si
  939.     pop cx
  940.     dec cx
  941.     jnz pp01ab
  942.  
  943.  
  944. ;-------- SWAP SCREENS
  945.     call pos
  946.     mov ax, yoff1
  947.     mov bx, yoff2
  948.     mov yoff2, ax
  949.     mov yoff1, bx
  950.     mov ax, soff1
  951.     mov bx, soff2
  952.     mov soff2, ax
  953.     mov soff1, bx
  954.  
  955.     ret
  956.  
  957. plotplasma  ENDP
  958.  
  959.  
  960. ;██▓▒░ ░    Wait for FULL vertical refresh
  961. waitv    PROC    NEAR
  962.  
  963.     mov dx, 3dah
  964. wv0:    in al, dx
  965.     test al, 8
  966.     jnz wv0
  967. wv1:    in al, dx
  968.     test al, 8
  969.     jz wv1
  970.  
  971.     ret
  972.  
  973. waitv    ENDP
  974.  
  975. ;----------------------------------------------------------------------------
  976.  
  977. ;██▓▒░ ░    Sine function returns bl=32767*sine(bl*360/1024)
  978. ;        (this is a rather detailed table, but the extra info helps the
  979. ;        granularity of the output a little)
  980.  
  981. sintable     dw   0 , 201 , 402 , 603 , 804 , 1005 , 1206 , 1407
  982.         dw   1608 , 1809 , 2009 , 2210 , 2410 , 2611 , 2811 , 3012 
  983.         dw   3212 , 3412 , 3612 , 3811 , 4011 , 4210 , 4410 , 4609 
  984.         dw   4808 , 5007 , 5205 , 5404 , 5602 , 5800 , 5998 , 6195 
  985.         dw   6393 , 6590 , 6786 , 6983 , 7179 , 7375 , 7571 , 7767 
  986.         dw   7962 , 8157 , 8351 , 8545 , 8739 , 8933 , 9126 , 9319 
  987.         dw   9512 , 9704 , 9896 , 10087 , 10278 , 10469 , 10659 , 10849 
  988.         dw   11039 , 11228 , 11417 , 11605 , 11793 , 11980 , 12167 , 12353 
  989.         dw   12539 , 12725 , 12910 , 13094 , 13279 , 13462 , 13645 , 13828 
  990.         dw   14010 , 14191 , 14372 , 14553 , 14732 , 14912 , 15090 , 15269 
  991.         dw   15446 , 15623 , 15800 , 15976 , 16151 , 16325 , 16499 , 16673 
  992.         dw   16846 , 17018 , 17189 , 17360 , 17530 , 17700 , 17869 , 18037 
  993.         dw   18204 , 18371 , 18537 , 18703 , 18868 , 19032 , 19195 , 19357 
  994.         dw   19519 , 19680 , 19841 , 20000 , 20159 , 20317 , 20475 , 20631 
  995.         dw   20787 , 20942 , 21096 , 21250 , 21403 , 21554 , 21705 , 21856 
  996.         dw   22005 , 22154 , 22301 , 22448 , 22594 , 22739 , 22884 , 23027 
  997.         dw   23170 , 23311 , 23452 , 23592 , 23731 , 23870 , 24007 , 24143 
  998.         dw   24279 , 24413 , 24547 , 24680 , 24811 , 24942 , 25072 , 25201 
  999.         dw   25329 , 25456 , 25582 , 25708 , 25832 , 25955 , 26077 , 26198 
  1000.         dw   26319 , 26438 , 26556 , 26674 , 26790 , 26905 , 27019 , 27133 
  1001.         dw   27245 , 27356 , 27466 , 27575 , 27683 , 27790 , 27896 , 28001 
  1002.         dw   28105 , 28208 , 28310 , 28411 , 28510 , 28609 , 28706 , 28803 
  1003.         dw   28898 , 28992 , 29085 , 29177 , 29268 , 29358 , 29447 , 29534 
  1004.         dw   29621 , 29706 , 29791 , 29874 , 29956 , 30037 , 30117 , 30195 
  1005.         dw   30273 , 30349 , 30424 , 30498 , 30571 , 30643 , 30714 , 30783 
  1006.         dw   30852 , 30919 , 30985 , 31050 , 31113 , 31176 , 31237 , 31297 
  1007.         dw   31356 , 31414 , 31470 , 31526 , 31580 , 31633 , 31685 , 31736 
  1008.         dw   31785 , 31833 , 31880 , 31926 , 31971 , 32014 , 32057 , 32098 
  1009.         dw   32137 , 32176 , 32213 , 32250 , 32285 , 32318 , 32351 , 32382 
  1010.         dw   32412 , 32441 , 32469 , 32495 , 32521 , 32545 , 32567 , 32589 
  1011.         dw   32609 , 32628 , 32646 , 32663 , 32678 , 32692 , 32705 , 32717 
  1012.         dw   32728 , 32737 , 32745 , 32752 , 32757 , 32761 , 32765 , 32766 
  1013.         dw   32767 , 32766 , 32765 , 32761 , 32757 , 32752 , 32745 , 32737 
  1014.         dw   32728 , 32717 , 32705 , 32692 , 32678 , 32663 , 32646 , 32628 
  1015.         dw   32609 , 32589 , 32567 , 32545 , 32521 , 32495 , 32469 , 32441 
  1016.         dw   32412 , 32382 , 32351 , 32318 , 32285 , 32250 , 32213 , 32176 
  1017.         dw   32137 , 32098 , 32057 , 32014 , 31971 , 31926 , 31880 , 31833 
  1018.         dw   31785 , 31736 , 31685 , 31633 , 31580 , 31526 , 31470 , 31414 
  1019.         dw   31356 , 31297 , 31237 , 31176 , 31113 , 31050 , 30985 , 30919 
  1020.         dw   30852 , 30783 , 30714 , 30643 , 30571 , 30498 , 30424 , 30349 
  1021.         dw   30273 , 30195 , 30117 , 30037 , 29956 , 29874 , 29791 , 29706 
  1022.         dw   29621 , 29534 , 29447 , 29358 , 29268 , 29177 , 29085 , 28992 
  1023.         dw   28898 , 28803 , 28706 , 28609 , 28510 , 28411 , 28310 , 28208 
  1024.         dw   28105 , 28001 , 27896 , 27790 , 27683 , 27575 , 27466 , 27356 
  1025.         dw   27245 , 27133 , 27019 , 26905 , 26790 , 26674 , 26556 , 26438 
  1026.         dw   26319 , 26198 , 26077 , 25955 , 25832 , 25708 , 25582 , 25456 
  1027.         dw   25329 , 25201 , 25072 , 24942 , 24811 , 24680 , 24547 , 24413 
  1028.         dw   24279 , 24143 , 24007 , 23870 , 23731 , 23592 , 23452 , 23311 
  1029.         dw   23170 , 23027 , 22884 , 22739 , 22594 , 22448 , 22301 , 22154 
  1030.         dw   22005 , 21856 , 21705 , 21554 , 21403 , 21250 , 21096 , 20942 
  1031.         dw   20787 , 20631 , 20475 , 20317 , 20159 , 20000 , 19841 , 19680 
  1032.         dw   19519 , 19357 , 19195 , 19032 , 18868 , 18703 , 18537 , 18371 
  1033.         dw   18204 , 18037 , 17869 , 17700 , 17530 , 17360 , 17189 , 17018 
  1034.         dw   16846 , 16673 , 16499 , 16325 , 16151 , 15976 , 15800 , 15623 
  1035.         dw   15446 , 15269 , 15090 , 14912 , 14732 , 14553 , 14372 , 14191 
  1036.         dw   14010 , 13828 , 13645 , 13462 , 13279 , 13094 , 12910 , 12725 
  1037.         dw   12539 , 12353 , 12167 , 11980 , 11793 , 11605 , 11417 , 11228 
  1038.         dw   11039 , 10849 , 10659 , 10469 , 10278 , 10087 , 9896 , 9704 
  1039.         dw   9512 , 9319 , 9126 , 8933 , 8739 , 8545 , 8351 , 8157 
  1040.         dw   7962 , 7767 , 7571 , 7375 , 7179 , 6983 , 6786 , 6590 
  1041.         dw   6393 , 6195 , 5998 , 5800 , 5602 , 5404 , 5205 , 5007 
  1042.         dw   4808 , 4609 , 4410 , 4210 , 4011 , 3811 , 3612 , 3412 
  1043.         dw   3212 , 3012 , 2811 , 2611 , 2410 , 2210 , 2009 , 1809 
  1044.         dw   1608 , 1407 , 1206 , 1005 , 804 , 603 , 402 , 201 
  1045.         dw   0 ,-201 ,-402 ,-603 ,-804 ,-1005 ,-1206 ,-1407 
  1046.         dw  -1608 ,-1809 ,-2009 ,-2210 ,-2410 ,-2611 ,-2811 ,-3012 
  1047.         dw  -3212 ,-3412 ,-3612 ,-3811 ,-4011 ,-4210 ,-4410 ,-4609 
  1048.         dw  -4808 ,-5007 ,-5205 ,-5404 ,-5602 ,-5800 ,-5998 ,-6195 
  1049.         dw  -6393 ,-6590 ,-6786 ,-6983 ,-7179 ,-7375 ,-7571 ,-7767 
  1050.         dw  -7962 ,-8157 ,-8351 ,-8545 ,-8739 ,-8933 ,-9126 ,-9319 
  1051.         dw  -9512 ,-9704 ,-9896 ,-10087 ,-10278 ,-10469 ,-10659 ,-10849 
  1052.         dw  -11039 ,-11228 ,-11417 ,-11605 ,-11793 ,-11980 ,-12167 ,-12353 
  1053.         dw  -12539 ,-12725 ,-12910 ,-13094 ,-13279 ,-13462 ,-13645 ,-13828 
  1054.         dw  -14010 ,-14191 ,-14372 ,-14553 ,-14732 ,-14912 ,-15090 ,-15269 
  1055.         dw  -15446 ,-15623 ,-15800 ,-15976 ,-16151 ,-16325 ,-16499 ,-16673 
  1056.         dw  -16846 ,-17018 ,-17189 ,-17360 ,-17530 ,-17700 ,-17869 ,-18037 
  1057.         dw  -18204 ,-18371 ,-18537 ,-18703 ,-18868 ,-19032 ,-19195 ,-19357 
  1058.         dw  -19519 ,-19680 ,-19841 ,-20000 ,-20159 ,-20317 ,-20475 ,-20631 
  1059.         dw  -20787 ,-20942 ,-21096 ,-21250 ,-21403 ,-21554 ,-21705 ,-21856 
  1060.         dw  -22005 ,-22154 ,-22301 ,-22448 ,-22594 ,-22739 ,-22884 ,-23027 
  1061.         dw  -23170 ,-23311 ,-23452 ,-23592 ,-23731 ,-23870 ,-24007 ,-24143 
  1062.         dw  -24279 ,-24413 ,-24547 ,-24680 ,-24811 ,-24942 ,-25072 ,-25201 
  1063.         dw  -25329 ,-25456 ,-25582 ,-25708 ,-25832 ,-25955 ,-26077 ,-26198 
  1064.         dw  -26319 ,-26438 ,-26556 ,-26674 ,-26790 ,-26905 ,-27019 ,-27133 
  1065.         dw  -27245 ,-27356 ,-27466 ,-27575 ,-27683 ,-27790 ,-27896 ,-28001 
  1066.         dw  -28105 ,-28208 ,-28310 ,-28411 ,-28510 ,-28609 ,-28706 ,-28803 
  1067.         dw  -28898 ,-28992 ,-29085 ,-29177 ,-29268 ,-29358 ,-29447 ,-29534 
  1068.         dw  -29621 ,-29706 ,-29791 ,-29874 ,-29956 ,-30037 ,-30117 ,-30195 
  1069.         dw  -30273 ,-30349 ,-30424 ,-30498 ,-30571 ,-30643 ,-30714 ,-30783 
  1070.         dw  -30852 ,-30919 ,-30985 ,-31050 ,-31113 ,-31176 ,-31237 ,-31297 
  1071.         dw  -31356 ,-31414 ,-31470 ,-31526 ,-31580 ,-31633 ,-31685 ,-31736 
  1072.         dw  -31785 ,-31833 ,-31880 ,-31926 ,-31971 ,-32014 ,-32057 ,-32098 
  1073.         dw  -32137 ,-32176 ,-32213 ,-32250 ,-32285 ,-32318 ,-32351 ,-32382 
  1074.         dw  -32412 ,-32441 ,-32469 ,-32495 ,-32521 ,-32545 ,-32567 ,-32589 
  1075.         dw  -32609 ,-32628 ,-32646 ,-32663 ,-32678 ,-32692 ,-32705 ,-32717 
  1076.         dw  -32728 ,-32737 ,-32745 ,-32752 ,-32757 ,-32761 ,-32765 ,-32766 
  1077.         dw  -32767 ,-32766 ,-32765 ,-32761 ,-32757 ,-32752 ,-32745 ,-32737 
  1078.         dw  -32728 ,-32717 ,-32705 ,-32692 ,-32678 ,-32663 ,-32646 ,-32628 
  1079.         dw  -32609 ,-32589 ,-32567 ,-32545 ,-32521 ,-32495 ,-32469 ,-32441 
  1080.         dw  -32412 ,-32382 ,-32351 ,-32318 ,-32285 ,-32250 ,-32213 ,-32176 
  1081.         dw  -32137 ,-32098 ,-32057 ,-32014 ,-31971 ,-31926 ,-31880 ,-31833 
  1082.         dw  -31785 ,-31736 ,-31685 ,-31633 ,-31580 ,-31526 ,-31470 ,-31414 
  1083.         dw  -31356 ,-31297 ,-31237 ,-31176 ,-31113 ,-31050 ,-30985 ,-30919 
  1084.         dw  -30852 ,-30783 ,-30714 ,-30643 ,-30571 ,-30498 ,-30424 ,-30349 
  1085.         dw  -30273 ,-30195 ,-30117 ,-30037 ,-29956 ,-29874 ,-29791 ,-29706 
  1086.         dw  -29621 ,-29534 ,-29447 ,-29358 ,-29268 ,-29177 ,-29085 ,-28992 
  1087.         dw  -28898 ,-28803 ,-28706 ,-28609 ,-28510 ,-28411 ,-28310 ,-28208 
  1088.         dw  -28105 ,-28001 ,-27896 ,-27790 ,-27683 ,-27575 ,-27466 ,-27356 
  1089.         dw  -27245 ,-27133 ,-27019 ,-26905 ,-26790 ,-26674 ,-26556 ,-26438 
  1090.         dw  -26319 ,-26198 ,-26077 ,-25955 ,-25832 ,-25708 ,-25582 ,-25456 
  1091.         dw  -25329 ,-25201 ,-25072 ,-24942 ,-24811 ,-24680 ,-24547 ,-24413 
  1092.         dw  -24279 ,-24143 ,-24007 ,-23870 ,-23731 ,-23592 ,-23452 ,-23311 
  1093.         dw  -23170 ,-23027 ,-22884 ,-22739 ,-22594 ,-22448 ,-22301 ,-22154 
  1094.         dw  -22005 ,-21856 ,-21705 ,-21554 ,-21403 ,-21250 ,-21096 ,-20942 
  1095.         dw  -20787 ,-20631 ,-20475 ,-20317 ,-20159 ,-20000 ,-19841 ,-19680 
  1096.         dw  -19519 ,-19357 ,-19195 ,-19032 ,-18868 ,-18703 ,-18537 ,-18371 
  1097.         dw  -18204 ,-18037 ,-17869 ,-17700 ,-17530 ,-17360 ,-17189 ,-17018 
  1098.         dw  -16846 ,-16673 ,-16499 ,-16325 ,-16151 ,-15976 ,-15800 ,-15623 
  1099.         dw  -15446 ,-15269 ,-15090 ,-14912 ,-14732 ,-14553 ,-14372 ,-14191 
  1100.         dw  -14010 ,-13828 ,-13645 ,-13462 ,-13279 ,-13094 ,-12910 ,-12725 
  1101.         dw  -12539 ,-12353 ,-12167 ,-11980 ,-11793 ,-11605 ,-11417 ,-11228 
  1102.         dw  -11039 ,-10849 ,-10659 ,-10469 ,-10278 ,-10087 ,-9896 ,-9704 
  1103.         dw  -9512 ,-9319 ,-9126 ,-8933 ,-8739 ,-8545 ,-8351 ,-8157 
  1104.         dw  -7962 ,-7767 ,-7571 ,-7375 ,-7179 ,-6983 ,-6786 ,-6590 
  1105.         dw  -6393 ,-6195 ,-5998 ,-5800 ,-5602 ,-5404 ,-5205 ,-5007 
  1106.         dw  -4808 ,-4609 ,-4410 ,-4210 ,-4011 ,-3811 ,-3612 ,-3412 
  1107.         dw  -3212 ,-3012 ,-2811 ,-2611 ,-2410 ,-2210 ,-2009 ,-1809 
  1108.         dw  -1608 ,-1407 ,-1206 ,-1005 ,-804 ,-603 ,-402 ,-201 
  1109.  
  1110. sine    PROC    NEAR
  1111.  
  1112.     and bx, 1023
  1113.     add bx, bx
  1114.     mov bx, cs:sintable[bx]
  1115.  
  1116.     ret
  1117.  
  1118. sine    ENDP
  1119.  
  1120.     END
  1121.